<template>
    <div class="sup">
        <el-menu :default-active="activePath" key="knk" class="el-menu-demo" mode="horizontal" @select="handle">
            <el-menu-item index="0" ref="nga">
                <img class="bunzz" v-if="ispas1" :src="ispas1 === 'SUCCESS' ? pasimg : ispas1 === 'ERROR' ? nopasimg : initimg">
                {{$t('perinf')}}
            </el-menu-item>
            <el-menu-item index="1" ref="nga">
                <img class="bunzz" v-if="ispas2" :src="ispas2 === 'SUCCESS' ? pasimg : ispas2 === 'ERROR' ? nopasimg : initimg">
                {{$t('comreginf')}}
            </el-menu-item>
            <el-menu-item index="2" ref="nga">
                <img class="bunzz" v-if="ispas3" :src="ispas3 === 'SUCCESS' ? pasimg : ispas3 === 'ERROR' ? nopasimg : initimg">
                {{$t('coracc')}}
            </el-menu-item>
            <el-menu-item index="3" ref="nga">
                <img class="bunzz" v-if="ispas4" :src="ispas4 === 'SUCCESS' ? pasimg : ispas4 === 'ERROR' ? nopasimg : initimg">
                {{$t('manmetinf')}}
            </el-menu-item>
            <el-menu-item index="4" ref="nga">
                <img class="bunzz" v-if="ispas5" :src="ispas5 === 'SUCCESS' ? pasimg : ispas5 === 'ERROR' ? nopasimg : initimg">
                {{$t('rsperinf')}}
            </el-menu-item>
            <el-button type="primary" v-if="kungfu" :disabled.sync="iscan" @click="next" v-preventReClick>{{$t('audcompd')}}</el-button>
        </el-menu>
        <router-view :key="this.$route.path" :iscan="iscan"></router-view>
        <el-dialog :title="$t('submtim')" :visible.sync="audDialogVisible" width="30%" center :modal-append-to-body="false">
            <el-input type="textarea" autosize v-model="firstAudit.auditRemark"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="audDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
                <el-button type="primary" @click="commitAud" v-preventReClick>{{$t('cfm')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {
    meraudit,
    comaud
} from '@/libs/reqlist.js'
export default {
    data () {
        return {
            ispas1: '',
            ispas2: '',
            ispas3: '',
            ispas4: '',
            ispas5: '',
            auditForm1: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            auditForm2: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            auditForm3: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            auditForm4: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            auditForm5: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            pasimg: require('@/assets/suc.png'),
            nopasimg: require('@/assets/err.png'),
            initimg: require('@/assets/lucency.png'),
            iscan: true,
            orderNum: '',
            keyl: false,
            kungfu: false,
            activePath: '0',
            operate: '',
            auditRemarks: '',
            active: 0,
            audDialogVisible: false,
            suc: {
                color: '#fff',
                background: '#67C23A'
            },
            err: {
                color: '#fff',
                background: '#F56C6C'
            },
            actPthbig: [
                '/sec/big/merAudit/pim',
                '/sec/big/merAudit/ownEnt',
                '/sec/big/merAudit/crpAcc',
                '/sec/big/merAudit/bnsInf',
                '/sec/big/merAudit/cpnBiz'
            ],
            firstAudit: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: ''
            },
            pnblist: [],
            auditData: {
                parentNo: null,
                auditStatus: null
            }
        }
    },
    methods: {
        iscannext1 (data) {
            this.ispas1 = data
        },
        iscannext2 (data) {
            this.ispas2 = data
        },
        iscannext3 (data) {
            this.ispas3 = data
        },
        iscannext4 (data) {
            this.ispas4 = data
        },
        iscannext5 (data) {
            this.ispas5 = data
        },
        handledisab () {
            this.iscan = false
        },
        async next() {
            if (window.localStorage.getItem('handlesp1') && window.localStorage.getItem('handlesp2') && window.localStorage.getItem('handlesp3') && window.localStorage.getItem('handlesp4') && window.localStorage.getItem('handlesp5')) {
                if (JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'SUCCESS' && JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus === 'SUCCESS' && JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'SUCCESS' && JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'SUCCESS' && JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus === 'SUCCESS') {
                    // if (JSON.parse(window.localStorage.getItem('handlesp1'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp1')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp2'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp2')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp3'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp3')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp4'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp4')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp5'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp5')))
                    this.auditData.parentNo = this.orderNum
                    this.auditData.auditStatus = 'SUCCESS'
                    comaud(JSON.stringify(this.auditData)).then(res => {
                        if (res.data.code === '000000') {
                            this.$message({
                                message: this.$t('audcompd'),
                                type: 'success'
                            })
                            window.sessionStorage.removeItem('audito')
                            window.localStorage.removeItem('handlesp1')
                            window.localStorage.removeItem('handlesp2')
                            window.localStorage.removeItem('handlesp3')
                            window.localStorage.removeItem('handlesp4')
                            window.localStorage.removeItem('handlesp5')
                            this.$router.push('/merApplyOrder/merAud')
                        }
                    })
                } else {
                    // if (JSON.parse(window.localStorage.getItem('handlesp1'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp1')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp2'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp2')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp3'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp3')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp4'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp4')))
                    // if (JSON.parse(window.localStorage.getItem('handlesp5'))) this.auditData.recordReqVos.push(JSON.parse(window.localStorage.getItem('handlesp5')))
                    this.auditData.parentNo = this.orderNum
                    this.auditData.auditStatus = 'ERROR'
                    comaud(JSON.stringify(this.auditData)).then(res => {
                        if (res.data.code === '000000') {
                            this.$message({
                                message: this.$t('audcompd'),
                                type: 'success'
                            })
                            window.sessionStorage.removeItem('audito')
                            window.localStorage.removeItem('handlesp1')
                            window.localStorage.removeItem('handlesp2')
                            window.localStorage.removeItem('handlesp3')
                            window.localStorage.removeItem('handlesp4')
                            window.localStorage.removeItem('handlesp5')
                            this.$router.push('/merApplyOrder/merAud')
                        }
                    })
                }
            } else {
                this.$message.error(this.$t('plscomaud'))
            }
        },
        async commitAud () {
            this.isRecheck = window.sessionStorage.getItem('recheck')
            this.firstAudit.orderNo = window.sessionStorage.getItem('handleOrder')
            await this.$http.post('merApplyOrder/getDetail', JSON.stringify({ parentOrderNo: this.firstAudit.orderNo }), 'application/json').then(res => {
            })
            this.audDialogVisible = false
        },
        handle (idx, path) {
            window.sessionStorage.setItem('step', idx)
            this.$router.push(this.actPthbig[idx - 0])
            this.activePath = idx
            if (this.activePath === '4') {
                if (this.$store.state.InReview.length === 5) {
                    this.keyl = false
                } else {
                    this.keyl = true
                }
            }
        },
        isagree (sta) {
            if (sta === 'SUCCESS' || sta === 'ERROR') {
                return true
            } else {
                return false
            }
        },
        getOrderFrm () {
            meraudit(JSON.stringify({ parentOrderNo: this.orderNum })).then(res => {
                if (res.data.code === '000000') {
                    this.pnblist = res.data.data
                    if (this.pnblist[0].auditStatus !== 'WAITCONFIRM' || this.pnblist[0].auditStatus !== 'TO_REVIEW') this.ispas1 = this.pnblist[0].auditStatus
                    if (this.pnblist[1].auditStatus !== 'WAITCONFIRM' || this.pnblist[1].auditStatus !== 'TO_REVIEW') this.ispas2 = this.pnblist[1].auditStatus
                    if (this.pnblist[2].auditStatus !== 'WAITCONFIRM' || this.pnblist[2].auditStatus !== 'TO_REVIEW') this.ispas3 = this.pnblist[2].auditStatus
                    if (this.pnblist[3].auditStatus !== 'WAITCONFIRM' || this.pnblist[3].auditStatus !== 'TO_REVIEW') this.ispas4 = this.pnblist[3].auditStatus
                    if (this.pnblist[4].auditStatus !== 'WAITCONFIRM' || this.pnblist[4].auditStatus !== 'TO_REVIEW') this.ispas5 = this.pnblist[4].auditStatus
                    if (this.ispas1 !== 'WAITCONFIRM') {
                        this.auditForm1.auditStatus = res.data.data[0].auditStatus
                        this.auditForm1.orderNo = res.data.data[0].orderNo
                        this.auditForm1.appType = res.data.data[0].applyType
                        this.auditForm1.auditRemark = res.data.data[0].auditRemark
                        window.localStorage.setItem('handlesp1', JSON.stringify(this.auditForm1))
                    }
                    if (this.ispas2 !== 'WAITCONFIRM') {
                        this.auditForm2.auditStatus = res.data.data[1].auditStatus
                        this.auditForm2.orderNo = res.data.data[1].orderNo
                        this.auditForm2.appType = res.data.data[1].applyType
                        this.auditForm2.auditRemark = res.data.data[1].auditRemark
                        window.localStorage.setItem('handlesp2', JSON.stringify(this.auditForm2))
                    }
                    if (this.ispas3 !== 'WAITCONFIRM') {
                        this.auditForm3.auditStatus = res.data.data[2].auditStatus
                        this.auditForm3.orderNo = res.data.data[2].orderNo
                        this.auditForm3.appType = res.data.data[2].applyType
                        this.auditForm3.auditRemark = res.data.data[2].auditRemark
                        window.localStorage.setItem('handlesp3', JSON.stringify(this.auditForm3))
                    }
                    if (this.ispas4 !== 'WAITCONFIRM') {
                        this.auditForm4.auditStatus = res.data.data[3].auditStatus
                        this.auditForm4.orderNo = res.data.data[3].orderNo
                        this.auditForm4.appType = res.data.data[3].applyType
                        this.auditForm4.auditRemark = res.data.data[3].auditRemark
                        window.localStorage.setItem('handlesp4', JSON.stringify(this.auditForm4))
                    }
                    if (this.ispas5 !== 'WAITCONFIRM') {
                        this.auditForm5.auditStatus = res.data.data[4].auditStatus
                        this.auditForm5.orderNo = res.data.data[4].orderNo
                        this.auditForm5.appType = res.data.data[4].applyType
                        this.auditForm5.auditRemark = res.data.data[4].auditRemark
                        window.localStorage.setItem('handlesp5', JSON.stringify(this.auditForm5))
                    }
                    if (this.isagree(this.ispas1) && this.isagree(this.ispas2) && this.isagree(this.ispas3) && this.isagree(this.ispas4) && this.isagree(this.ispas5)) {
                        this.handledisab()
                    }
                }
            })
        }
    },
    mounted () {
        this.orderNum = window.sessionStorage.getItem('handleOrder')
        this.operate = window.sessionStorage.getItem('operate')
        if (window.sessionStorage.getItem('step')) this.activePath = window.sessionStorage.getItem('step')
        this.$router.push(this.actPthbig[this.activePath - 0])
        if (this.operate === 'review') {
            this.kungfu = true
            if (window.localStorage.getItem('handlesp1')) this.ispas1 = JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus
            if (window.localStorage.getItem('handlesp2')) this.ispas2 = JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus
            if (window.localStorage.getItem('handlesp3')) this.ispas3 = JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus
            if (window.localStorage.getItem('handlesp4')) this.ispas4 = JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus
            if (window.localStorage.getItem('handlesp5')) this.ispas5 = JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus
            this.getOrderFrm()
        }
        if (this.operate === 'examine') {
            this.kungfu = false
            this.getOrderFrm()
        }
        this.auditRemarks = this.$store.state.auditRemarks
    },
    destroyed () {
        window.sessionStorage.removeItem('audito')
        window.localStorage.removeItem('handlesp1')
        window.localStorage.removeItem('handlesp2')
        window.localStorage.removeItem('handlesp3')
        window.localStorage.removeItem('handlesp4')
        window.localStorage.removeItem('handlesp5')
        window.sessionStorage.removeItem('size')
        window.sessionStorage.removeItem('operate')
        window.sessionStorage.removeItem('handleOrder')
        window.sessionStorage.removeItem('orderSta')
    }
}
</script>

<style lang="less" scoped>
@import './merAuditBig.less';
</style>
